# coding: utf-8
import datetime
from ibm import db



class InterResult(db.Model):
    __tablename__ = 'inter_result'

    resume_id = db.Column(db.ForeignKey('resume.resume_id'), primary_key=True, nullable=False)
    result = db.Column(db.String(20))
    band = db.Column(db.String(10))
    post = db.Column(db.String(10))
    comment = db.Column(db.String(255))
    time = db.Column(db.DateTime)
    ability = db.Column(db.String(255))
    inter_id = db.Column(db.ForeignKey('user.user_id'), primary_key=True, nullable=False, index=True)

    inter = db.relationship('User', primaryjoin='InterResult.inter_id == User.user_id', backref='inter_results')
    resume = db.relationship('Resume', primaryjoin='InterResult.resume_id == Resume.resume_id', backref='inter_results')



class Operation(db.Model):
    __tablename__ = 'operation'

    resume_id = db.Column(db.ForeignKey('resume.resume_id'), primary_key=True, nullable=False)
    add_man = db.Column(db.ForeignKey('user.user_id'), primary_key=True, nullable=False, index=True)
    review_man = db.Column(db.ForeignKey('user.user_id'), primary_key=True, nullable=False, index=True)
    add_comment = db.Column(db.String(255))
    review_result = db.Column(db.String(4))
    review_comment = db.Column(db.String(255))
    add_time = db.Column(db.DateTime,default=datetime.datetime.now)
    review_time = db.Column(db.DateTime)

    user = db.relationship('User', primaryjoin='Operation.add_man == User.user_id', backref='user_operations')
    resume = db.relationship('Resume', primaryjoin='Operation.resume_id == Resume.resume_id', backref='operations')
    user1 = db.relationship('User', primaryjoin='Operation.review_man == User.user_id', backref='user_operations_0')

    def __init__(self, id, add_man,review_man, add_comment=None, result=None,
                 review_comment=None, add_time=None, review_time=None):
        self.resume_id=id
        self.add_man = add_man
        self.review_man = review_man
        self.add_comment = add_comment
        self.review_result = result
        self.review_comment = review_comment
        self.add_time = add_time
        self.review_time = review_time


class Resume(db.Model):
    __tablename__ = 'resume'

    resume_id = db.Column(db.Integer, primary_key=True, unique=True)
    name = db.Column(db.String(20), nullable=False)
    age = db.Column(db.Integer, nullable=False)
    sex = db.Column(db.String(4), nullable=False, server_default=db.FetchedValue())
    tel = db.Column(db.String(20))
    education = db.Column(db.String(10))
    gradu_time = db.Column(db.String(10))
    gradu_school = db.Column(db.String(20))
    major = db.Column(db.String(25))
    tech = db.Column(db.String(20))
    language = db.Column(db.String(20))
    now_com = db.Column(db.String(20))
    re_from = db.Column(db.String(20))
    file = db.Column(db.String(100))
    status = db.Column(db.String(20), default='等待Review')
    interview_times = db.Column(db.Integer, default='0')
    def __init__(self, id=None, name=None, age=None, sex=None, tel=None, education=None, gradu_time=None,
                 gradu_school=None, major=None, tech=None, language=None, now_com=None, re_from=None, file=None,status=None,interview_times=None):
        self.resume_id = id
        self.name = name
        self.age = age
        self.sex = sex
        self.tel = tel
        self.education = education
        self.gradu_time = gradu_time
        self.gradu_school = gradu_school
        self.major = major
        self.tech = tech
        self.language = language
        self.now_com = now_com
        self.re_from = re_from
        self.file = file
        self.status = status
        self.interview_times = interview_times

class User(db.Model):
    __tablename__ = 'user'

    user_id = db.Column(db.String(20), primary_key=True)
    password = db.Column(db.String(25), nullable=False)
    name = db.Column(db.String(25), nullable=False)
    tel = db.Column(db.String(20), nullable=False)
    role = db.Column(db.String(20), nullable=False, server_default=db.FetchedValue())
    in_time = db.Column(db.DateTime)
    head_img = db.Column(db.String(30))


# flask-sqlacodegen "mysql+pymysql://root:密码@127.0.0.1/ibm10" -
# -outfile "ibm\models.py"  --flask
# flask --app .\ibm\runserver.py  db init
# flask --app .\ibm\runserver.py  db migrate
# flask --app .\ibm\runserver.py  db upgrade
